home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Workspace / MonsterShelf / Source / Controller.m < prev    next >
Text File  |  1995-06-12  |  5KB  |  210 lines

  1. #import "Controller.h"
  2. #import "ShelfView.h"
  3.  
  4. #import <appkit/appkit.h>
  5.  
  6.  
  7. @implementation Controller
  8.  
  9. - init
  10. {
  11.     infoPanel = nil;
  12.     prefPanel = nil;
  13.  
  14.     return self;
  15. }
  16.  
  17.  
  18. - appDidInit:sender
  19. {
  20.     NXRect    contentRect;
  21.     NXScreen    *screens;
  22.     int        screenCount;
  23.     id        shelfWindow;
  24.     id        workspace = [Application workspace];
  25.     char    *mountedList = NULL;
  26.  
  27. #if    1 || WORK_AROUND_WORKSPACE_BUG
  28.     /*
  29.      *  This code works around a Workspace bug in 3.0 that prevents Workspace
  30.      *  from dealing with disks effectively if it gets a request for icons
  31.      *  before it's really initialized.  Calling this method before getting
  32.      *  icons allows Workspace to initialize itself correctly.  The bug is
  33.      *  fixed in 3.1, so we can eventually delete this code.
  34.      */
  35.     {
  36.     BOOL junk;
  37.     char *desc = NULL, *fsType = NULL;
  38.     [[Application workspace] getInfoForFileSystemAt:"/"
  39.             isRemovable:&junk  isWritable:&junk
  40.             isUnmountable:&junk description:&desc
  41.             type:&fsType];
  42.     if (desc)
  43.         free(desc);
  44.     if (fsType)
  45.         free(fsType);
  46.     }
  47. #endif    
  48.  
  49.     [NXApp getScreens:&screens count:&screenCount];
  50.  
  51.     shelfWindow = [[Window allocFromZone:[self zone]]
  52.             initContent:&screens[0].screenBounds
  53.             style:NX_TOKENSTYLE
  54.             backing:NX_BUFFERED buttonMask:0 defer:NO];
  55.     
  56.     [[shelfWindow contentView] getFrame:&contentRect];
  57.     shelfView = [[ShelfView allocFromZone:[shelfWindow zone]]
  58.             initFrame:&contentRect];
  59.     [[shelfWindow setContentView:shelfView] free];
  60.  
  61.     PSsetwindowlevel(-2147483647, [shelfWindow windowNum]);
  62.  
  63.     [shelfWindow setAvoidsActivation:YES];
  64.     [NXApp preventWindowOrdering];
  65.  
  66.     [shelfWindow display];
  67.     [shelfWindow orderBack:self];
  68.  
  69.     /*
  70.      *  UI is up and initialized.  Do some other things:
  71.      *    1) scan for mounted things that we should stick up on the UI
  72.      *       NOTE: because we couldn't get the list of removable media
  73.      *             prior to 3.1, we need to be careful.
  74.      *    2) start listening for changes in the file system
  75.      */
  76.     if ([workspace respondsTo:@selector(getMountedRemovableMedia:)] &&
  77.         [workspace getMountedRemovableMedia:&mountedList])
  78.         [self perform:@selector(createViewFor:) withPaths:mountedList];
  79.  
  80.     if (mountedList)
  81.         free(mountedList);
  82.  
  83.     [workspace beginListeningForDeviceStatusChanges];
  84.     [NXApp hide:self];
  85.  
  86.     return self;
  87. }
  88.  
  89.  
  90. /*
  91.  *  Put up a panel.  We have to handle two cases:
  92.  *  1) The panel is not present because it hasn't been loaded yet, or
  93.  *     because the user closed a previous one.  In this case, we load the
  94.  *     panel from the nib section.
  95.  *  2) The panel hasn't been closed by the user.  In this case, just
  96.  *     pop up the window.
  97.  */
  98. - doPanel:(id *)panel named:(const char *) name
  99. {
  100.     char    path[MAXPATHLEN];
  101.     id        bundle = [NXBundle mainBundle];
  102.  
  103.     if (!*panel && [bundle getPath:path forResource:name ofType:"nib"])
  104.     [NXApp loadNibFile:path owner:self withNames:NO fromZone:[self zone]];
  105.         
  106.     [*panel makeKeyAndOrderFront:self];
  107.  
  108.     return self;
  109. }
  110.  
  111.  
  112. - doInfo:sender
  113. {
  114.     return [self doPanel:&infoPanel named:"Info"];
  115. }
  116.  
  117.  
  118. - doPreferences:sender
  119. {
  120.     [self doPanel:&prefPanel named:"Preferences"];
  121.  
  122.     [gridValue setIntValue:[shelfView gridValue]];
  123.     if ([shelfView gridEnabled])
  124.     [gridSwitch setState:YES];
  125.  
  126.     return self;
  127. }
  128.  
  129.  
  130. /*
  131.  *  Find out if a window just closed.  If it was the info panel or the pref
  132.  *  panel, forget about its identity, since it will free itself on close.
  133.  */
  134. - windowWillClose:sender
  135. {
  136.     if (sender == infoPanel)
  137.     infoPanel = nil;
  138.     else if (sender == prefPanel) {
  139.         [self enableGrid:self];            /* make sure we're in sync */
  140.         prefPanel = nil;
  141.     }
  142.  
  143.     return self;
  144. }
  145.  
  146.  
  147. - enableGrid:sender
  148. {
  149.     unsigned int    newValue = [gridValue intValue];
  150.  
  151.     [shelfView setGridValue:newValue];
  152.     if ([shelfView gridValue] != newValue)
  153.     [gridValue setIntValue:[shelfView gridValue]];
  154.  
  155.     [shelfView setGridEnabled:[gridSwitch state]];
  156.  
  157.     return self;
  158. }
  159.  
  160.  
  161. - createViewFor:(const char *) fullPath
  162. {
  163.     [shelfView createViewForPath:fullPath at:NULL];
  164.     return self;
  165. }
  166.  
  167.  
  168. - app:sender mounted:(const char *) fullPath
  169. {
  170.     [self createViewFor:fullPath];
  171.     return self;
  172. }
  173.  
  174.  
  175. - app:sender unmounted:(const char *) fullPath
  176. {
  177.     [shelfView removeViewForPath:fullPath];
  178.     return self;
  179. }
  180.  
  181. @end
  182.  
  183.  
  184. @implementation Object(BriansPathMethods)
  185. - (void) perform:(SEL) sel withPaths:(const char *) paths
  186. {
  187.     const char    *scan = paths;
  188.     char    *copy;
  189.     char    aPath[MAXPATHLEN];
  190.  
  191.     if (!paths || !*paths)
  192.         return;
  193.  
  194.     do {
  195.         copy = aPath;
  196.  
  197.         while (*scan && *scan != '\t')
  198.         *copy++ = *scan++;
  199.         *copy = '\0';
  200.  
  201.         if (*scan == '\t')
  202.         scan++;
  203.  
  204.     [self perform:sel with:(id) aPath];
  205.  
  206.     } while (*scan);
  207. }
  208. @end
  209.  
  210.